package addon.w3.mdx.com;

import java.io.IOException;
import java.util.Vector;

import addon.w3.mdx.LEDataInputStream;
import addon.w3.mdx.MDXException;
import addon.w3.mdx.MDXParentCOM;

/**
 * MTLS						// [Materials]
	long	nbytes;
	struct {
		long	nbytesi;
		long	PriorityPlane;
		long	RenderMode;		(+1:ConstantColor;+16:SortPrimsFarZ;+32:FullResolution)
		LAYS
	} materials[nmtls];
 * @author madjk
 *
 */
public class MDXMaterials extends MDXParentCOM {
	int length = -1;
	public Vector mtls = null;
	
	public String getTag() {
		return "MTLS";
	}
	
	public void _decode(LEDataInputStream ins) throws IOException, MDXException {
		length = ins.readInt();
		while(true) {
			byte temp[] = new byte[16];
			ins.read(temp);
			ins.unread(temp);
			String layTag = new String(temp,12,4);
			if(layTag.equals("LAYS")) {
				MDXMaterialCOM mdcom = new MDXMaterialCOM();
				mdcom.decode(ins);
				if(mtls == null) mtls = new Vector();
				mtls.add(mdcom);
			} else {
				break;
			}
		}
		//System.out.println( " CHECK BANSHEE : " +((MDXMaterialCOM)coms.get(3)).lay.lays[0].toString() );
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("TAG : "+getTag());
		sb.append("\n\tELEN : "+length);
		if(mtls != null && mtls.size() > 0) {
			sb.append("\n\tMaterials[] : "+mtls.size());
			for (int i = 0; i < mtls.size(); i++) {
				MDXMaterialCOM com = (MDXMaterialCOM)mtls.get(i);
				sb.append("("+com.lay.lays.length+")");
			}
		}
		return sb.toString();
	}

	@Override
	public boolean isImplicitTag() {
		// TODO Auto-generated method stub
		return true;
	}
}